from flask import Flask, request, jsonify, Blueprint
from service import modelService_v3
from service.modelService_v3 import oled_expert, search_assistant, summary_assistant, gpt4, models


model_v3_bp = Blueprint('model_v3', __name__, url_prefix='/model_v3')

@model_v3_bp.route('/generate', methods=['POST'])
def generate_text():
    data = request.get_json()
    model_name = data.get('model')
    prompt = data.get('prompt')

    if not model_name or not prompt:
        return jsonify({"error": "Missing model or prompt"}), 400

    if model_name not in models:
        return jsonify({"error": "Invalid model"}), 400

    model = models[model_name]
    response = model.generate(prompt)
    return jsonify({"response": response})

@model_bp.route('/hello', methods=['POST'])
def hello():
    data = request.get_json()
    question = data.get('question')
    answer = data.get('answer')
    return jsonify({
        "msg": "success",
        "code": 0,
        "data": {
            "question": question,
            "answer": answer,
             "precision": 2.6,
            "complete": 2.2,
            "useful": 2.5
        }
    })
# 请求单个问题答案的评分
@model_bp.route('/querySingleQuestion', methods=['POST'])
def querySingleQuestion():
    data = request.get_json()
    question = data.get('question')
    answer = data.get('answer')
    ai_score_precision, ai_score_complete, ai_score_useful = modelService.run_eval_exp(question,answer)
    return jsonify({
        "msg":"success",
        "code": 0,
        "data": {
            "precision": ai_score_precision,
            "complete": ai_score_complete,
            "useful": ai_score_useful
        }
    })

